package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.mapper.StudentSubjectTeacherMapper;
import com.example.demo.model.StudentSubjectTeacherDto;
import com.example.demo.service.IStudentSubjectTeacherService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 题目 服务实现类
 * </p>
 *
 * @author liwei
 * @since 2024-11-20
 */
@Service
public class StudentSubjectTeacherServiceImpl extends ServiceImpl<StudentSubjectTeacherMapper, StudentSubjectTeacherDto> implements IStudentSubjectTeacherService {

    @Autowired
    private StudentSubjectTeacherMapper studentSubjectTeacherMapper;

    /* *
     * @Title: getStudentSubjectTeachers
     * @Author: admin
     * @Date: 2024-11-27 11:36:07
     * @Params: [requ]
     * @Return: List<StudentSubjectTeacherDto>
     * @Description: 师生双选列表 --- 不分页
     */
    @Override
    public List<StudentSubjectTeacherDto> getStudentSubjectTeachers(StudentSubjectTeacherDto requ) {

        //List<StudentSubjectTeacherDto> studentSubjectTeacherDtos = studentSubjectTeacherMapper.getStudentSubjectTeachers(requ);
        QueryWrapper qw = new QueryWrapper();
        qw.eq("sy.academic_year_id", requ.getAcademicYearId() );
        if (StringUtils.isNotBlank(requ.getStudentName())){
            qw.like("s.student_name", requ.getStudentName());
        }
        if (requ.getSubjectAuditStates()!= null && requ.getSubjectAuditStates().size() > 0 ) {
            qw.in("s2.subject_audit_state", requ.getSubjectAuditStates());
        }

        List<StudentSubjectTeacherDto> studentSubjectTeacherDtos  = studentSubjectTeacherMapper.getStudentSubjectTeachers(qw);
        return studentSubjectTeacherDtos;

    }

    /* *
     * @Title: getStudentSubjectTeachersByPage
     * @Author: admin
     * @Date: 2024-11-27 16:28:52
     * @Params:  
     * @Return: null
     * @Description: 师生双选列表 --- mybatisplus分页
     */
    @Override
    public Page<StudentSubjectTeacherDto> getStudentSubjectTeachersByPage(StudentSubjectTeacherDto requ) {

        QueryWrapper qw = new QueryWrapper();
        qw.eq("sy.academic_year_id", requ.getAcademicYearId() );
        if (StringUtils.isNotBlank(requ.getStudentName())){
            qw.like("s.student_name", requ.getStudentName());
        }
        if (requ.getSubjectAuditStates()!= null && requ.getSubjectAuditStates().size() > 0 ) {
            qw.in("s2.subject_audit_state", requ.getSubjectAuditStates());
        }

        Page<StudentSubjectTeacherDto> studentSubjectTeacherDtoPage = studentSubjectTeacherMapper.getStudentSubjectTeachers(requ.build(),qw);
        return studentSubjectTeacherDtoPage;
    }
}
